//
//  SpecialDetailViewController.m
//  IntimateGift
//
//  Created by 蔡宏业 on 14/12/19.
//  Copyright (c) 2014年 蔡宏业. All rights reserved.
//

#import "SpecialDetailViewController.h"
#import "SpecialCell.h"
#import "UIImageView+WebCache.h"
#import "Special.h"
#import "ChoicenessCell.h"
#import "AllButtonWebViewController.h"
#import "NetHandler.h"
#import "ChoicenessCell.h"
#import "AllButtonController.h"
//tableView
@interface SpecialDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)NSMutableArray *arr;
@property (nonatomic,retain)UITableView *table;

@end

@implementation SpecialDetailViewController

- (void)dealloc
{
    [_special release];
    [_arr release];
//    [_array release];
    [_table release];
    [super dealloc];
}
- (void)handleData
{
    
    //专题数据的网络请求
    //专题图片解析
    
    
    //专题数据的网络请求
    
    //专题图片解析
    
    NSString *str = @"http://api.liwushuo.com/v1/collections?limit=100&offset=0";
    [NetHandler getDataWithUrl:str completion:^(NSData *data) {
        NSError *error = nil;
        id  result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
        
        NSDictionary *dic = [[NSDictionary alloc]init];
        dic = [result objectForKey:@"data"];
        NSArray *arr = [NSArray array];
        arr = [dic objectForKey:@"collections"];
        self.arr = [NSMutableArray array];
        //        Special *hehe = [[Special alloc]init];
        for (NSDictionary *dictemp in arr) {
            //利用字典将对象初始化
            Special *hehe =[[Special alloc]initWithDictionary:dictemp];
            [self.arr addObject:hehe];
            
        }
        [self installTable];
    }];
    //对象，个性，场合的网络数据请求
    
    
}

- (void)installTable
{
    
    self.table = [[UITableView alloc]initWithFrame:self.view.bounds     style:(UITableViewStylePlain)];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    [_table release];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"全部主题";
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    [self handleData];
 }


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.view.bounds.size.height / 3.0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SpecialCell *cell = [tableView dequeueReusableCellWithIdentifier:@"re"];
    if (cell == nil) {
        cell = [[[SpecialCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"re"] autorelease];
    }
    
    Special *spec = [self.arr objectAtIndex:indexPath.row];

    cell.name.text = spec.title;//崩
    [cell.pic setImageWithURL:[NSURL URLWithString:spec.cover_image_url] placeholderImage:[UIImage imageNamed:@"zhanwei.jpg"]];
    [self.view addSubview:cell];
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 传值 pus
    AllButtonController *allVC = [[AllButtonController alloc] init];
    Special *special =  [self.arr objectAtIndex:indexPath.row];
    allVC.special = special;
    [self.navigationController pushViewController:allVC animated:YES];
    [allVC release];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
